package com.fone.player.online.fragment;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;

import com.fone.player.ApplicationManage;
import com.fone.player.R;
import com.fone.player.activity.BaseFragment;
import com.fone.player.client.Callback;
import com.fone.player.client.Error;
import com.fone.player.client.HotspotRst;
import com.fone.player.client.HotspotRst.Module;
import com.fone.player.client.Request;
import com.fone.player.client.RstSerializer;
import com.fone.player.online.adapter.HotAdapter;
import com.fone.player.util.FoneUtil;
import com.fone.player.util.L;
import com.fone.player.util.SharedPreferenceOnline;
import com.fone.player.widget.xlistview.XListView;
import com.fone.player.widget.xlistview.XListView.IXListViewListener;

//import com.fone.player.online.adapter.HotAdapter;

/**
 * 全网热点标签页。
 */
public class HotFragment extends BaseFragment implements IXListViewListener {
	/** 日志标签 */
	private static final String TAG = "HotFragment";

	private View mView;
	private View footView;
	private XListView mListView;

	private HotAdapter hotAdapter;

	private RstSerializer rstSerializer;
	private SharedPreferenceOnline sp;

	private HotspotRst t;

	private String shost;
	private String host;
	private ArrayList<Module> moduleList = new ArrayList<Module>();

	private static final int SUCCESS = 0;
	private static final int FAILURE = 1;

	private final int UPDATELOCAL = 0;
	private final int UPDATESERVER = 1;

	private View mProgressContainer;
	private View mEmptyView;
	private boolean mContentShown;

	private void ensureContent() {
		if (mListView != null && mProgressContainer != null) {
			return;
		}
		View root = getView();
		if (root == null) {
			throw new IllegalStateException("Content view not yet created");
		}
		mProgressContainer = root.findViewById(R.id.progress);
		if (mProgressContainer == null) {
			throw new RuntimeException("Your content must have a ViewGroup whose id attribute is 'R.id.progress_container'");
		}

		mEmptyView = root.findViewById(R.id.empty);
		if (mEmptyView != null) {
			mEmptyView.setVisibility(View.GONE);
		}
		mContentShown = true;

	}

	public void setContentEmpty(boolean isEmpty) {
		ensureContent();
		if (mListView == null) {
			throw new IllegalStateException("List view must be initialized before");
		}
		if (isEmpty) {
			mEmptyView.setVisibility(View.VISIBLE);
			mListView.setVisibility(View.GONE);
		} else {
			mEmptyView.setVisibility(View.GONE);
			mListView.setVisibility(View.VISIBLE);
		}

	}

	private void setContentShown(boolean shown) {
		ensureContent();
		if (mContentShown == shown) {
			return;
		}
		mContentShown = shown;
		if (shown) {

			// mProgressContainer.startAnimation(AnimationUtils.loadAnimation(getActivity(),
			// android.R.anim.fade_out));
			// mListView.startAnimation(AnimationUtils.loadAnimation(getActivity(),
			// android.R.anim.fade_in));

			mProgressContainer.setVisibility(View.GONE);
			mListView.setVisibility(View.VISIBLE);
		} else {

			// mProgressContainer.startAnimation(AnimationUtils.loadAnimation(getActivity(),
			// android.R.anim.fade_in));
			// mListView.startAnimation(AnimationUtils.loadAnimation(getActivity(),
			// android.R.anim.fade_out));

			mProgressContainer.setVisibility(View.VISIBLE);
			mListView.setVisibility(View.GONE);
		}
	}

	private Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {

			case UPDATELOCAL:
				if (getView() != null) {

					updateHot(true, t);
					setContentShown(true);
				}
				break;

			case UPDATESERVER:
				if (getView() != null) {
					onRefresh();
				}
				break;

			default:
				break;
			}
		}
	};

	public static HotFragment newInstance(String url, String id) {
		HotFragment f = new HotFragment();

		Bundle args = new Bundle();
		args.putString("url", url);
		args.putString("id", id);
		f.setArguments(args);
		return f;
	}

	public String getShownUrl() {
		return getArguments().getString("url");
	}

	public String getShownId() {
		return getArguments().getString("id");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		L.v(TAG, "---- onCreateView ----");

		mView = inflater.inflate(R.layout.fragment_hot, container, false);
		footView = inflater.inflate(R.layout.hot_footer, null);

		return mView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub

		super.onActivityCreated(savedInstanceState);

		L.v(TAG, "---- onActivityCreated ----");
		initView();

	}

	@Override
	public void onStart() {
		super.onStart();
		L.v(TAG, "---- onStart ----");

		if (moduleList.isEmpty()) {
			initData();
		}
	}

	private void initView() {
		mListView = (XListView) mView.findViewById(R.id.list);

		mListView.setPullLoadEnable(false);
		mListView.setPullRefreshEnable(true);
		mListView.setEnableDragLoadMore(false);
		mListView.setXListViewListener(this);
		// mListView.setOnScrollListener(this);

		hotAdapter = new HotAdapter(getActivity(), host, shost, moduleList);
		mListView.setAdapter(hotAdapter, true);
		mListView.addFooterView(footView);
	}

	private void initData() {

		// 当缓存为空时，向服务器申请数据
		// if(TextUtils.isEmpty(localStr)){
		// mHandler.sendEmptyMessage(UPDATESERVER);
		// }else{
		setContentShown(false);

		new Thread(new Runnable() {
			@Override
			public void run() {
				
				String localStr = null;
				rstSerializer = new RstSerializer();
				sp = new SharedPreferenceOnline(ApplicationManage.getAplicationManageInstance(), "全网热点");
				localStr = sp.getData();

				if (isSerializer(localStr)) {
					mHandler.sendEmptyMessage(UPDATELOCAL);
					// 当有网且缓存数据超时，重新申请数据
					if (isTimeOut(sp.getTime(), System.currentTimeMillis())) {
						mHandler.sendEmptyMessage(UPDATESERVER);
					}
				} else {
					mHandler.sendEmptyMessage(UPDATESERVER);
				}
			}
		}).start();

		// }
	}

	/**
	 * 向服务器申请数据
	 */
	private void initHotData() {
		L.v(TAG, "HotCallBack", "initData()");
		// 如果没有网络，则不向服务器申请数据
		if (getActivity() != null && FoneUtil.isNetOkWithToast(getActivity())) {
			Request.getInstance().hotspot(new HotCallBack());
		} else {
			setContentShown(true);
		}
	}

	private class HotCallBack implements Callback<HotspotRst> {

		@Override
		public void onSuccess(HotspotRst t) {
			if (destory) {
				return;
			}
			mListView.stopRefresh();
			mListView.stopLoadMore();
			setContentShown(true);
			updateHot(false, t);
		}

		@Override
		public void onFailure(Error error) {
			if (destory) {
				return;
			}
			mListView.stopRefresh();
			mListView.stopLoadMore();
			setContentShown(true);
			showShortToast("当前无新内容，请稍后刷新重试.");
			L.v(TAG, "HotCallBack", "-onFailure-" + error.toString());
		}
	}

	private void updateHot(boolean isLocal, HotspotRst t) {
		L.v(TAG, "HotCallBack", "-onSuccess-" + t.result);
		if (getActivity() != null) {
			if (t.result == SUCCESS) {

				if (!isLocal) {
					sp.setAll(System.currentTimeMillis(), rstSerializer.toString(t));
				}

				moduleList.clear();
				getServerData(t);
				frashColumnListView(t);

			} else if (t.result == FAILURE) {
			}
		}

	}

	/**
	 * 刷新"列表"数据
	 */
	private void frashColumnListView(HotspotRst t) {
		if (t.modules != null && t.modules.moduleList != null && t.modules.moduleList.size() > 0) {
			moduleList.addAll((ArrayList<Module>) t.modules.moduleList);
			hotAdapter.setData(host, shost, moduleList);

			// mListView.removeAllViews();
			//
			// View view;
			//
			// for (Module module : moduleList) {
			//
			// String type = module.type.trim();
			//
			// if (type.equals("1")) {
			// if (isListEmpty(module)) {
			// view = viewError();
			// } else {
			// view = viewOne((ArrayList<Cnt>) module.cnts.cntList);
			// }
			// } else if (type.equals("2")) {
			//
			// if (isListEmpty(module)) {
			// view = viewError();
			// } else {
			// view = viewTwo((ArrayList<Cnt>) module.cnts.cntList);
			// }
			//
			// } else if (type.equals("3")) {
			// view = viewThree(module);
			// } else if (type.equals("4")) {
			//
			// if (isListEmpty(module)) {
			// view = viewError();
			// } else {
			// view = viewFour((ArrayList<Cnt>) module.cnts.cntList);
			// }
			//
			// } else if (type.equals("5")) {
			//
			// if (isListEmpty(module)) {
			// view = viewError();
			// } else {
			// view = viewFive((ArrayList<Cnt>) module.cnts.cntList);
			// }
			//
			// } else if (type.equals("6")) {
			//
			// if (isListEmpty(module)) {
			// view = viewError();
			// } else {
			// view = viewSix(module);
			// }
			//
			// } else if (type.equals("7")) {
			//
			// if (isListEmpty(module)) {
			// view = viewError();
			// } else {
			// view = viewSeven((ArrayList<Cnt>) module.cnts.cntList);
			// }
			//
			// } else {
			// view = viewError();
			// }
			// mListView.addView(view);
			// }
			//

		}
	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		mListView.onLoad();
		if (FoneUtil.isNetOkWithToast(getActivity())) {
			Request.getInstance().hotspot(new HotCallBack());
		} else {

			mListView.stopRefresh();
			mListView.stopLoadMore();
			setContentShown(true);
		}
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
	}

	/**
	 * 将字符串反序列化
	 */
	private boolean isSerializer(String data) {
		try {
			t = (HotspotRst) rstSerializer.fromString(HotspotRst.class, data);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * 判断缓存是否过期
	 */
	private boolean isTimeOut(Long sptime, Long currenttime) {
		long num = (long) ((currenttime - sptime) / 60000);
		return num > 15;
	}

	/**
	 * 初始化服务器返回参数
	 */
	private void getServerData(HotspotRst t) {
		// TODO Auto-generated method stub
		if (t.shost != null) {
			shost = t.shost;
			Request.getInstance().setSHost(shost);
			L.v(TAG, "getServerData", "-shost-" + shost);
		}

		if (t.host != null) {
			host = t.host;
			L.v(TAG, "getServerData", "-host-" + host);
		}
	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		System.out.println(TAG + "---- onAttach ----");

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		System.out.println(TAG + "---- onCreate ----");

	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		System.out.println(TAG + "---- onResume ----");

	}

	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		System.out.println(TAG + "---- onPause ----");

	}

	@Override
	public void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		System.out.println(TAG + "---- onStop ----");

	}

	/**
	 * Detach from view.
	 */
	@Override
	public void onDestroyView() {
		mContentShown = false;

		mProgressContainer = mEmptyView = null;
		destory = true;

		rstSerializer = null;
		if (mListView != null) {
			mListView.removeAllViewsInLayout();
		}

		mListView = null;

		super.onDestroyView();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		System.out.println(TAG + "---- onDestroy ----");

	}

	@Override
	public void onDetach() {
		// TODO Auto-generated method stub
		super.onDetach();
		System.out.println(TAG + "---- onDetach ----");

	}

	// private boolean isListEmpty(Module module) {
	// // TODO Auto-generated method stub
	// if (module.cnts != null && module.cnts.cntList != null &&
	// module.cnts.cntList.size() > 0) {
	// return false;
	// } else {
	// return true;
	// }
	//
	// }
	//
	// /**
	// * 模板一（海报页）
	// */
	// private View viewOne(List<Cnt> cntList) {
	//
	//
	// PostersView poster = new PostersView(getActivity());
	// poster.setLayoutParams(new
	// AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
	// ScreenUtil.dp2px(210)));
	//
	// if (cntList != null && cntList.size() > 0) {
	// poster.initData(true, shost, cntList);
	// }
	//
	// return poster;
	// }
	//
	// /**
	// * 模板二的holder
	// *
	// * @author kongxiaojun
	// * @since 2014-6-20
	// */
	// private class ViewHolderTwo {
	// public RelativeLayout layout1;
	// public ImageView pic1;
	// public TextView name1;
	// public TextView time1;
	//
	// public RelativeLayout layout2;
	// public ImageView pic2;
	// public TextView name2;
	// public TextView time2;
	//
	// public RelativeLayout layout3;
	// public ImageView pic3;
	// public TextView name3;
	// public TextView time3;
	//
	// public RelativeLayout layout4;
	// public ImageView pic4;
	// public TextView name4;
	// public TextView time4;
	//
	// public RelativeLayout layout5;
	// public ImageView pic5;
	// public TextView name5;
	// public TextView time5;
	//
	// public RelativeLayout layout6;
	// public ImageView pic6;
	// public TextView name6;
	// public TextView time6;
	//
	// public ViewHolderTwo(RelativeLayout layout1, ImageView pic1, TextView
	// name1, TextView time1, RelativeLayout layout2, ImageView pic2, TextView
	// name2, TextView time2, RelativeLayout layout3, ImageView pic3, TextView
	// name3, TextView time3, RelativeLayout layout4, ImageView pic4,
	// TextView name4, TextView time4, RelativeLayout layout5, ImageView pic5,
	// TextView name5, TextView time5, RelativeLayout layout6, ImageView pic6,
	// TextView name6, TextView time6) {
	// super();
	// this.layout1 = layout1;
	// this.pic1 = pic1;
	// this.name1 = name1;
	// this.time1 = time1;
	// this.layout2 = layout2;
	// this.pic2 = pic2;
	// this.name2 = name2;
	// this.time2 = time2;
	// this.layout3 = layout3;
	// this.pic3 = pic3;
	// this.name3 = name3;
	// this.time3 = time3;
	// this.layout4 = layout4;
	// this.pic4 = pic4;
	// this.name4 = name4;
	// this.time4 = time4;
	// this.layout5 = layout5;
	// this.pic5 = pic5;
	// this.name5 = name5;
	// this.time5 = time5;
	// this.layout6 = layout6;
	// this.pic6 = pic6;
	// this.name6 = name6;
	// this.time6 = time6;
	// }
	// }
	//
	// /**
	// * 模板二 此页面类似一个gridvied，但是感觉没必要使用gridView; 有更好的话，请补充。
	// */
	// private View viewTwo(ArrayList<Cnt> cntList) {
	//
	// View view2 =
	// LayoutInflater.from(getActivity()).inflate(R.layout.item_hot_two, null);
	// ViewHolderTwo holderTwo = new ViewHolderTwo((RelativeLayout)
	// view2.findViewById(R.two.layout_one), (ImageView)
	// view2.findViewById(R.two.pic_one), (TextView)
	// view2.findViewById(R.two.time_one), (TextView)
	// view2.findViewById(R.two.name_one), (RelativeLayout)
	// view2.findViewById(R.two.layout_two),
	// (ImageView) view2.findViewById(R.two.pic_two), (TextView)
	// view2.findViewById(R.two.time_two), (TextView)
	// view2.findViewById(R.two.name_two), (RelativeLayout)
	// view2.findViewById(R.two.layout_three), (ImageView)
	// view2.findViewById(R.two.pic_three),
	// (TextView) view2.findViewById(R.two.time_three), (TextView)
	// view2.findViewById(R.two.name_three), (RelativeLayout)
	// view2.findViewById(R.two.layout_four), (ImageView)
	// view2.findViewById(R.two.pic_four), (TextView)
	// view2.findViewById(R.two.time_four),
	// (TextView) view2.findViewById(R.two.name_four), (RelativeLayout)
	// view2.findViewById(R.two.layout_five), (ImageView)
	// view2.findViewById(R.two.pic_five), (TextView)
	// view2.findViewById(R.two.time_five), (TextView)
	// view2.findViewById(R.two.name_five),
	// (RelativeLayout) view2.findViewById(R.two.layout_six), (ImageView)
	// view2.findViewById(R.two.pic_six), (TextView)
	// view2.findViewById(R.two.time_six), (TextView)
	// view2.findViewById(R.two.name_six));
	//
	//
	// // 第一页
	// if (cntList != null && cntList.size() > 0) {
	// Cnt cnt = cntList.get(0);
	// // 设置图片
	// setImageView(holderTwo.pic1, R.drawable.default_image_bg, cnt.pic1);
	// holderTwo.name1.setText(cnt.name);
	// holderTwo.time1.setText(cnt.timelen.substring(0, 5));
	//
	// holderTwo.layout1.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderTwo.pic1.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第二页
	// if (cntList != null && cntList.size() > 1) {
	// Cnt cnt = cntList.get(1);
	// // 设置图片
	// setImageView(holderTwo.pic2, R.drawable.default_image_bg, cnt.pic1);
	// holderTwo.name2.setText(cnt.name);
	// holderTwo.time2.setText(cnt.timelen.substring(0, 5));
	//
	// holderTwo.layout2.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderTwo.pic2.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第三页
	// if (cntList != null && cntList.size() > 2) {
	// Cnt cnt = cntList.get(2);
	// // 设置图片
	// setImageView(holderTwo.pic3, R.drawable.default_image_bg, cnt.pic1);
	// holderTwo.name3.setText(cnt.name);
	// holderTwo.time3.setText(cnt.timelen.substring(0, 5));
	//
	// holderTwo.layout3.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderTwo.pic3.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第四页
	// if (cntList != null && cntList.size() > 3) {
	// Cnt cnt = cntList.get(3);
	// // 设置图片
	// setImageView(holderTwo.pic4, R.drawable.default_image_bg, cnt.pic1);
	// holderTwo.name4.setText(cnt.name);
	// holderTwo.time4.setText(cnt.timelen.substring(0, 5));
	//
	// holderTwo.layout4.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderTwo.pic4.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第五页
	// if (cntList != null && cntList.size() > 4) {
	// Cnt cnt = cntList.get(4);
	// // 设置图片
	// setImageView(holderTwo.pic5, R.drawable.default_image_bg, cnt.pic1);
	// holderTwo.name5.setText(cnt.name);
	// holderTwo.time5.setText(cnt.timelen.substring(0, 5));
	//
	// holderTwo.layout5.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderTwo.pic5.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第六页
	// if (cntList != null && cntList.size() > 5) {
	// Cnt cnt = cntList.get(5);
	// // 设置图片
	// setImageView(holderTwo.pic6, R.drawable.default_image_bg, cnt.pic1);
	// holderTwo.name6.setText(cnt.name);
	// holderTwo.time6.setText(cnt.timelen.substring(0, 5));
	//
	// holderTwo.layout6.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderTwo.pic6.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// return view2;
	// }
	//
	// private View view3;
	// /**
	// * 模版3 holder
	// */
	// private ViewHolderThree holderThree;
	//
	// /**
	// * 模版3 holder
	// *
	// * @author kongxiaojun
	// * @since 2014-6-20
	// */
	// private class ViewHolderThree {
	// public TextView name;
	// public RelativeLayout layout;
	//
	// public ViewHolderThree(TextView name, RelativeLayout layout) {
	// super();
	// this.name = name;
	// this.layout = layout;
	// }
	// }
	//
	// /**
	// * 模板三
	// */
	// private View viewThree(Module module) {
	// if (view3 == null) {
	// view3 =
	// LayoutInflater.from(getActivity()).inflate(R.layout.item_hot_three,
	// null);
	// holderThree = new ViewHolderThree((TextView)
	// view3.findViewById(R.three.name),
	// (RelativeLayout)view3.findViewById(R.three.layout_more));
	// }
	//
	// if (TextUtils.isEmpty(module.url)) {
	// holderThree.layout.setVisibility(View.GONE);
	// } else {
	// holderThree.layout.setOnClickListener(new MoreClicker(module.url));
	// }
	// holderThree.name.setText(module.name);
	// return view3;
	// }
	//
	// private View view4;
	// private ViewHolderFour holderFour;
	//
	// /**
	// * 模版4 holder
	// *
	// * @author kongxiaojun
	// * @since 2014-6-20
	// */
	// private class ViewHolderFour {
	// public TextView name;
	// public TextView rmTxt;
	// public ImageView type;
	// public ImageView pic;
	// public ImageView rmPic;
	//
	// public ViewHolderFour(TextView name, TextView rmTxt, ImageView type,
	// ImageView pic, ImageView rmPic) {
	// super();
	// this.name = name;
	// this.rmTxt = rmTxt;
	// this.type = type;
	// this.pic = pic;
	// this.rmPic = rmPic;
	// }
	// }
	//
	// /**
	// * 模板四
	// */
	// private View viewFour(ArrayList<Cnt> cntList) {
	// if (view4 == null) {
	// view4 =
	// LayoutInflater.from(getActivity()).inflate(R.layout.item_hot_four, null);
	// holderFour = new ViewHolderFour((TextView)
	// view4.findViewById(R.four.name), (TextView)
	// view4.findViewById(R.four.from), (ImageView)
	// view4.findViewById(R.four.type), (ImageView)
	// view4.findViewById(R.four.pic), (ImageView)
	// view4.findViewById(R.four.from_pic));
	// }
	// if (cntList != null && cntList.get(0) != null) {
	// Cnt cnt = cntList.get(0);
	// // 设置图片
	// setImageView(holderFour.pic, R.drawable.default_image_bg, cnt.pic2);
	// holderFour.name.setText(cnt.name);
	// if (cnt.ftv.equals("1")) {
	// holderFour.type.setVisibility(View.VISIBLE);
	// }
	// // holderFour.type.setText(getType(cnt.ftv, cnt.favtyp));
	// getRmd(cnt.rmd, cnt.rmdval, holderFour.rmTxt, holderFour.rmPic);
	// holderFour.pic.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderFour.pic.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	// return view4;
	// }
	//
	// private View view5;
	// /**
	// * 模版5 viewholder
	// */
	// private ViewHolderFive holderFive;
	//
	// /**
	// * 模版5 viewholder
	// *
	// * @author kongxiaojun
	// * @since 2014-6-20
	// */
	// private class ViewHolderFive {
	// public RelativeLayout oneLayout;
	// public TextView nameOne;
	// public TextView rmTxtOne;
	// public TextView typeOne;
	// public ImageView picOne;
	// public ImageView rmPicOne;
	//
	// public RelativeLayout twoLayout;
	// public TextView nameTwo;
	// public TextView rmTxtTwo;
	// public TextView typeTwo;
	// public ImageView picTwo;
	// public ImageView rmPicTwo;
	//
	// public ViewHolderFive(RelativeLayout oneLayout, TextView nameOne,
	// TextView rmTxtOne, TextView typeOne, ImageView picOne, ImageView
	// rmPicOne, RelativeLayout twoLayout, TextView nameTwo, TextView rmTxtTwo,
	// TextView typeTwo, ImageView picTwo, ImageView rmPicTwo) {
	// super();
	// this.oneLayout = oneLayout;
	// this.nameOne = nameOne;
	// this.rmTxtOne = rmTxtOne;
	// this.typeOne = typeOne;
	// this.picOne = picOne;
	// this.rmPicOne = rmPicOne;
	// this.twoLayout = twoLayout;
	// this.nameTwo = nameTwo;
	// this.rmTxtTwo = rmTxtTwo;
	// this.typeTwo = typeTwo;
	// this.picTwo = picTwo;
	// this.rmPicTwo = rmPicTwo;
	// }
	//
	// }
	//
	// /**
	// * 模板五
	// */
	// private View viewFive(ArrayList<Cnt> cntList) {
	// if (view5 == null) {
	// view5 =
	// LayoutInflater.from(getActivity()).inflate(R.layout.item_hot_five, null);
	// holderFive = new ViewHolderFive((RelativeLayout)
	// view5.findViewById(R.five.layout_one), (TextView)
	// view5.findViewById(R.five.name_one), (TextView)
	// view5.findViewById(R.five.from_one), (TextView)
	// view5.findViewById(R.five.type_one), (ImageView)
	// view5.findViewById(R.five.pic_one),
	// (ImageView) view5.findViewById(R.five.from_one_pic), (RelativeLayout)
	// view5.findViewById(R.five.layout_two), (TextView)
	// view5.findViewById(R.five.name_two), (TextView)
	// view5.findViewById(R.five.from_two), (TextView)
	// view5.findViewById(R.five.type_two),
	// (ImageView) view5.findViewById(R.five.pic_two), (ImageView)
	// view5.findViewById(R.five.from_two_pic));
	// }
	//
	// // 第一页
	// if (cntList != null && cntList.size() > 0) {
	// Cnt cnt = cntList.get(0);
	// // 设置图片
	// setImageView(holderFive.picOne, R.drawable.default_image_bg, cnt.pic2);
	// holderFive.nameOne.setText(cnt.name);
	// getRmd(cnt.rmd, cnt.rmdval, holderFive.rmTxtOne, holderFive.rmPicOne);
	// // holderFive.typeOne.setText(getType(cnt.ftv, cnt.favtyp));
	// setType(cnt.ftv, cnt.favtyp, holderFive.typeOne);
	//
	// holderFive.oneLayout.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderFive.picOne.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第二页
	// if (cntList != null && cntList.size() > 1) {
	// Cnt cnt = cntList.get(1);
	// // 设置图片
	// setImageView(holderFive.picTwo, R.drawable.default_image_bg, cnt.pic2);
	// holderFive.nameTwo.setText(cnt.name);
	// getRmd(cnt.rmd, cnt.rmdval, holderFive.rmTxtTwo, holderFive.rmPicTwo);
	// // holderFive.typeTwo.setText(getType(cnt.ftv, cnt.favtyp));
	// setType(cnt.ftv, cnt.favtyp, holderFive.typeTwo);
	//
	// holderFive.twoLayout.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderFive.picTwo.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// return view5;
	// }
	//
	// private View view6;
	// private ViewHolderSex holderSex;
	//
	// /**
	// * 模版6 viewholder
	// *
	// * @author kongxiaojun
	// * @since 2014-6-20
	// */
	// private class ViewHolderSex {
	// public ImageView from;
	// public RelativeLayout moreLayout;
	// public TextView nameOne;
	// public ImageView picOne;
	// public TextView nameTwo;
	// public ImageView picTwo;
	// public TextView nameThree;
	// public ImageView picThree;
	//
	// public ViewHolderSex(ImageView from, RelativeLayout moreLayout, TextView
	// nameOne, ImageView picOne, TextView nameTwo, ImageView picTwo, TextView
	// nameThree, ImageView picThree) {
	// super();
	// this.from = from;
	// this.moreLayout = moreLayout;
	// this.nameOne = nameOne;
	// this.picOne = picOne;
	// this.nameTwo = nameTwo;
	// this.picTwo = picTwo;
	// this.nameThree = nameThree;
	// this.picThree = picThree;
	// }
	// }
	//
	// /**
	// * 模板六
	// */
	// private View viewSix(Module module) {
	// if (view6 == null) {
	// view6 = LayoutInflater.from(getActivity()).inflate(R.layout.item_hot_six,
	// null);
	// holderSex = new ViewHolderSex((ImageView)
	// view6.findViewById(R.six.pic_from),
	// (RelativeLayout)view6.findViewById(R.six.more), (TextView)
	// view6.findViewById(R.six.name_one), (ImageView)
	// view6.findViewById(R.six.pic_one),
	// (TextView) view6.findViewById(R.six.name_two), (ImageView)
	// view6.findViewById(R.six.pic_two), (TextView)
	// view6.findViewById(R.six.name_three), (ImageView)
	// view6.findViewById(R.six.pic_three));
	// }
	//
	// if (TextUtils.isEmpty(module.url)) {
	// holderSex.moreLayout.setVisibility(View.GONE);
	//
	// } else {
	// holderSex.moreLayout.setOnClickListener(new MoreClicker(module.url));
	// }
	// // 设置来源图片
	// setImageView(holderSex.from, R.drawable.default_image_bg, module.pic);
	//
	// ArrayList<Cnt> cntList = (ArrayList<Cnt>) module.cnts.cntList;
	//
	// // 第一页
	// if (cntList != null && cntList.size() > 0) {
	// Cnt cnt = cntList.get(0);
	// // 设置图片
	// setImageView(holderSex.picOne, R.drawable.default_image_bg, cnt.pic2);
	// holderSex.nameOne.setText(cnt.name);
	// holderSex.picOne.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderSex.picOne.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第二页
	// if (cntList != null && cntList.size() > 1) {
	// Cnt cnt = cntList.get(1);
	// // 设置图片
	// setImageView(holderSex.picTwo, R.drawable.default_image_bg, cnt.pic2);
	// holderSex.nameTwo.setText(cnt.name);
	// holderSex.picTwo.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderSex.picTwo.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第三页
	// if (cntList != null && cntList.size() > 2) {
	// Cnt cnt = cntList.get(2);
	// // 设置图片
	// setImageView(holderSex.picThree, R.drawable.default_image_bg, cnt.pic2);
	// holderSex.nameThree.setText(cnt.name);
	//
	// holderSex.picThree.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderSex.picThree.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// return view6;
	// }
	//
	// private View view7;
	// private ViewHolderSeven holderSeven;
	//
	// private class ViewHolderSeven {
	// public TextView nameOne;
	// public TextView typeOne;
	// public TextView fromOne;
	// public ImageView picOne;
	// public ImageView picfromOne;
	// public TextView nameTwo;
	// public TextView typeTwo;
	// public TextView fromTwo;
	// public ImageView picTwo;
	// public ImageView picfromTwo;
	// public TextView nameThree;
	// public TextView typeThree;
	// public TextView fromThree;
	// public ImageView picThree;
	// public ImageView picfromThree;
	//
	// public ViewHolderSeven(TextView nameOne, TextView typeOne, TextView
	// fromOne, ImageView picOne, ImageView picfromOne, TextView nameTwo,
	// TextView typeTwo, TextView fromTwo, ImageView picTwo, ImageView
	// picfromTwo, TextView nameThree, TextView typeThree, TextView fromThree,
	// ImageView picThree,
	// ImageView picfromThree) {
	// super();
	// this.nameOne = nameOne;
	// this.typeOne = typeOne;
	// this.fromOne = fromOne;
	// this.picOne = picOne;
	// this.picfromOne = picfromOne;
	// this.nameTwo = nameTwo;
	// this.typeTwo = typeTwo;
	// this.fromTwo = fromTwo;
	// this.picTwo = picTwo;
	// this.picfromTwo = picfromTwo;
	// this.nameThree = nameThree;
	// this.typeThree = typeThree;
	// this.fromThree = fromThree;
	// this.picThree = picThree;
	// this.picfromThree = picfromThree;
	// }
	// }
	//
	// /**
	// * 模板七
	// */
	// private View viewSeven(ArrayList<Cnt> cntList) {
	// if (view7 == null) {
	// view7 =
	// LayoutInflater.from(getActivity()).inflate(R.layout.item_hot_seven,
	// null);
	// holderSeven = new ViewHolderSeven((TextView)
	// view7.findViewById(R.seven.name_one), (TextView)
	// view7.findViewById(R.seven.type_one), (TextView)
	// view7.findViewById(R.seven.from_one), (ImageView)
	// view7.findViewById(R.seven.pic_one), (ImageView)
	// view7.findViewById(R.seven.from_one_pic),
	// (TextView) view7.findViewById(R.seven.name_two), (TextView)
	// view7.findViewById(R.seven.type_two), (TextView)
	// view7.findViewById(R.seven.from_two), (ImageView)
	// view7.findViewById(R.seven.pic_two), (ImageView)
	// view7.findViewById(R.seven.from_two_pic),
	// (TextView) view7.findViewById(R.seven.name_three), (TextView)
	// view7.findViewById(R.seven.type_three), (TextView)
	// view7.findViewById(R.seven.from_three), (ImageView)
	// view7.findViewById(R.seven.pic_three), (ImageView)
	// view7.findViewById(R.seven.from_three_pic));
	// }
	//
	// // 第一页
	//
	// if (cntList != null && cntList.size() > 0) {
	// Cnt cnt = cntList.get(0);
	// setImageView(holderSeven.picOne, R.drawable.default_image_bg, cnt.pic2);
	// holderSeven.nameOne.setText(cnt.name);
	// getRmd(cnt.rmd, cnt.rmdval, holderSeven.fromOne, holderSeven.picfromOne);
	// // holderSeven.typeOne.setText(getType(cnt.ftv, cnt.favtyp));
	//
	// setType(cnt.ftv, cnt.favtyp, holderSeven.typeOne);
	//
	// holderSeven.picOne.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderSeven.picOne.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第二页
	// if (cntList != null && cntList.size() > 1) {
	// Cnt cnt = cntList.get(1);
	// setImageView(holderSeven.picTwo, R.drawable.default_image_bg, cnt.pic2);
	// holderSeven.nameTwo.setText(cnt.name);
	// getRmd(cnt.rmd, cnt.rmdval, holderSeven.fromTwo, holderSeven.picfromTwo);
	// // holderSeven.typeTwo.setText(getType(cnt.ftv, cnt.favtyp));
	//
	// setType(cnt.ftv, cnt.favtyp, holderSeven.typeTwo);
	//
	// holderSeven.picTwo.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderSeven.picTwo.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// // 第三页
	// if (cntList != null && cntList.size() > 2) {
	// Cnt cnt = cntList.get(2);
	// setImageView(holderSeven.picThree, R.drawable.default_image_bg,
	// cnt.pic2);
	// holderSeven.nameThree.setText(cnt.name);
	// getRmd(cnt.rmd, cnt.rmdval, holderSeven.fromThree,
	// holderSeven.picfromThree);
	// // holderSeven.typeThree.setText(getType(cnt.ftv, cnt.favtyp));
	// setType(cnt.ftv, cnt.favtyp, holderSeven.typeThree);
	//
	// holderSeven.picThree.setOnClickListener(new OnClicker(cnt));
	// } else {
	// holderSeven.picThree.setBackgroundResource(R.drawable.com_btn_orange);
	// }
	//
	// return view7;
	// }
	//
	// /**
	// * 错误页面
	// */
	// private View viewError() {
	// View view =
	// LayoutInflater.from(getActivity()).inflate(R.layout.item_hot_error,
	// null);
	// return view;
	// }

	// DisplayImageOptions options = new DisplayImageOptions.Builder()
	// .showImageOnLoading(R.drawable.default_image_bg)
	// .showImageForEmptyUri(R.drawable.default_image_bg)
	// .showImageOnFail(R.drawable.default_image_bg)
	// .cacheInMemory(true)
	// .cacheOnDisk(true)
	// .considerExifParams(true)
	// .build();
	//
	// /**
	// * 设置图片
	// */
	// private void setImageView(ImageView imageView, int defaultResourceId,
	// String url) {
	// // 设置图片
	// if (!TextUtils.isEmpty(url) && url.length() > 7) {
	// //ImageDownloadModule.getInstance().download(FoneUtil.getAbsoluteUrl("",
	// shost, url), defaultResourceId, imageView);
	// ImageLoader.getInstance().displayImage(FoneUtil.getAbsoluteUrl("", shost,
	// url), imageView, options);
	// }
	// }
	//
	// /**
	// * 推荐维度 0 无纬度 1 时长 2 评分 3 更新至 4 自定义文字 5 自定义图片
	// */
	// private void getRmd(String rmd, String rmdval, TextView textView,
	// ImageView imageView) {
	// if (rmd.equals("1")) {
	// textView.setText("播放时长"+rmdval.substring(0, 5));
	// } else if (rmd.equals("2")) {
	// textView.setText(rmdval + "分");
	// } else if (rmd.equals("3")) {
	// textView.setText(rmdval);
	// } else if (rmd.equals("4")) {
	// textView.setText(rmdval);
	// } else if (rmd.equals("5")) {
	// setImageView(imageView, R.drawable.default_image_bg, rmdval);
	// imageView.setVisibility(View.VISIBLE);
	// } else {
	//
	// }
	// }
	//
	// /**
	// * 显示当前影片类型
	// *
	// * 当影片为收费视频时，显示VIP 否则显示对应类型
	// *
	// * ftv 当前视频是否收费 0 否 1 是 favtyp 收藏类型，内容类型(0 全部 1 电影 2 电视剧 3 动漫 4 综艺 5 原创 6
	// * 视频直播 7 音频直播 8 新闻 9 短片)
	// */
	// private void setType(String ftv, String favtyp, TextView textview) {
	//
	// if (TextUtils.isEmpty(ftv) || TextUtils.isEmpty(favtyp)) {
	// } else if (ftv.equals("1")) {
	// textview.setVisibility(View.VISIBLE);
	// textview.setText("VIP");
	// }else{
	//
	// }
	// // if (favtyp.equals("0")) {
	// // return "全部";
	// // } else if (favtyp.equals("1")) {
	// // return "电影";
	// // } else if (favtyp.equals("2")) {
	// // return "电视剧";
	// // } else if (favtyp.equals("3")) {
	// // return "动漫";
	// // } else if (favtyp.equals("4")) {
	// // return "综艺";
	// // } else if (favtyp.equals("5")) {
	// // return "原创 ";
	// // } else if (favtyp.equals("6")) {
	// // return "视频直播";
	// // } else if (favtyp.equals("7")) {
	// // return "音频直播 ";
	// // } else if (favtyp.equals("8")) {
	// // return "新闻";
	// // } else if (favtyp.equals("9")) {
	// // return "短片";
	// // }
	// // else {
	// // return "";
	// // }
	//
	// }
	//
	// /**
	// * 控件相应监听
	// */
	// private class OnClicker implements OnClickListener {
	// Cnt cnt;
	//
	// public OnClicker(Cnt cnt) {
	// super();
	// if (cnt != null) {
	// this.cnt = cnt;
	// }
	// }
	//
	// @Override
	// public void onClick(View arg0) {
	// // TODO Auto-generated method stub
	// // 判断网络状态
	// if (FoneUtil.isNetOk(getActivity())) {
	// Activity2poster.startActivity(getActivity(), getRedirectInfo(cnt));
	// }
	// }
	// }
	//
	// private RedirectInfo getRedirectInfo(Cnt cnt) {
	// RedirectInfo redirectInfo = new RedirectInfo();
	// redirectInfo.host = host;
	// redirectInfo.utp = cnt.utp;
	// redirectInfo.weibourl = cnt.weibourl;
	// redirectInfo.url = cnt.url;
	// redirectInfo.vgurl = cnt.url;
	// redirectInfo.xyzplayurl = cnt.url;
	// redirectInfo.dnfs = cnt.dfnt;
	// redirectInfo.name = cnt.name;
	// redirectInfo.ourl = cnt.ourl;
	// redirectInfo.btnply = cnt.btnply;
	// redirectInfo.pic = cnt.pic2;
	// return redirectInfo;
	// }
	//
	// private class MoreClicker implements OnClickListener {
	//
	// String url;
	//
	// public MoreClicker(String url) {
	// super();
	// this.url = url;
	// }
	//
	// @Override
	// public void onClick(View v) {
	// // TODO Auto-generated method stub
	// // 判断网络状态
	// if (FoneUtil.isNetOk(getActivity())) {
	// Intent intent = new Intent(getActivity(), SubjectActivity.class);
	// intent.putExtra("url", url);
	// getActivity().startActivity(intent);
	// }
	// }
	//
	// }

}
